﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using MvvmEx.Controls.Calendar;
using MvvmEx.Controls.Messager;
using MvvmEx.EventArgs;
using MvvmEx.Test.Enums;

namespace MvvmEx.Test.Views
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window, INotifyPropertyChanged
    {
        private int _i = 0;

        public MainView()
        {
            InitializeComponent();

            this.DataContext = this;

            DateTimes = new ObservableCollection<DateTime>();

            DateTimes.Add(DateTime.Now.AddDays(-1));
            DateTimes.Add(DateTime.Now.AddDays(-2));
            DateTimes.Add(DateTime.Now.AddDays(-3));

            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Txt.Focus();
        }

        private int _totalCount = 500;
        private int _pageIndex = 1;
        private int _totalPage = 25;
        private int _pageSize = 20;
        private ObservableCollection<DateTime> _dateTimes;
        private TestDefine _state = TestDefine.First;

        public TestDefine State
        {
            get { return _state; }
            set
            {
                _state = value;
                OnPropertyChanged();
            }
        }

        public ObservableCollection<DateTime> DateTimes
        {
            get { return _dateTimes; }
            set
            {
                _dateTimes = value;
                OnPropertyChanged();
            }
        }

        public int TotalCount
        {
            get
            {
                return _totalCount;
            }
            set
            {
                _totalCount = value;
                OnPropertyChanged();
            }
        }

        public int PageIndex
        {
            get
            {
                return _pageIndex;
            }
            set
            {
                _pageIndex = value;
                OnPropertyChanged();
            }
        }

        public int TotalPage
        {
            get
            {
                return _totalPage;
            }
            set
            {
                _totalPage = value;
                OnPropertyChanged();
            }
        }

        public int PageSize
        {
            get
            {
                return _pageSize;
            }
            set
            {
                _pageSize = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private void Pager_OnPageChanged(object sender, PageChangedEventArg e)
        {
            var x = e.PageIndex;
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            Messager.ShowInfoMsg("提示", "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest");
        }

        private void ButtonBase_OnClick2(object sender, RoutedEventArgs e)
        {
            Messager.ShowConfirmMsg("提示", "确定删除么？", result =>
             {

             });
        }

        private void MarkerCalendar_OnAdd(object sender, RoutedEventArgs<MarkerCalendarDataItem> e)
        {

        }

        private void MarkerCalendar_OnUpdate(object sender, RoutedEventArgs<MarkerCalendarDataItem> e)
        {

        }


        private void DateShow_OnDateChanged(object sender, RoutedEventArgs<DateTime> e)
        {

        }

        private void DateShow_OnSelectedDateChanged(object sender, RoutedEventArgs<DateTime> e)
        {

        }


        private void NotifyBtn_OnClick(object sender, RoutedEventArgs e)
        {
            NotifyManager.ShowNotify(new NotifyMsg()
            {
                Title = "提示",
                Content = $"这是第{_i++}条消息",
                DelAction = () =>
                {
                    NotifyManager.ShowNotify(new NotifyMsg()
                    {
                        Title = "xxx",
                        Content = "哈哈哈"
                    });
                }
            });
        }

        private void MarkerCalendar_OnDelete(object sender, RoutedEventArgs<MarkerCalendarDataItem> e)
        {
            NotifyManager.ShowNotify(new NotifyMsg()
            {
                Title = "删除",
                Content = $"日历删除了",
            });
        }
    }
}
